alert("由于服务器到期以及图书馆系统的即将更新，本网页即将于十月暂停使用，多谢谅解！");
let idList = [];
let id = 0;
let uid = '';
let pwd = '';
let seatid = '';
//
// function init() {
//     $.ajax({
//         url: "userseat/getUser",
//         type: "get",
//         dataType: "json",
//         success: function (data) {
//             console.log(data);
//             idList = data
//         }
//     })
// }
//
// function isHave(index) {
//     for (const id in idList) {
//         if (id == index) {
//             return true
//         }
//     }
//     return false
// }

function login() {
    // console.log(isHave(1))
    uid = $("#uid").val()
    pwd = $("#pwd").val()
    $.ajax({
        url: "userseat/login",
        type: "post",
        dataType: "json",
        data: {
            "uid": uid,
            "pwd": pwd
        },
        success: function (data) {
            console.log(data);
            if(data[0]==null){
                alert("用户名和密码错误！请重新登录")
                window.location.reload();
            }else{
                id=data[0]
                seatid=data[1]
                $("#login").toggle()
                $("#uid1").html("【学号】"+uid+"<br>【当前座位号】"+seatid)
                $("#sid").val(seatid)
                $("#update").toggle()
            }

        }
    })
}

function upd() {
    // console.log(isHave(1))
    seatid=$("#sid").val()
    if(seatid>400||seatid<=0){
        alert("座位号不符合规定，请重新登录！");
        window.location.reload();
    }
    const userseat={
        "id":id,
        "uid": uid,
        "pwd": pwd,
        "seatid": seatid
    }
    $.ajax({
        url: "userseat/aou",
        type: "get",
        dataType: "json",
        data: userseat,
        success: function (data) {
            if (data){
                alert("修改成功")
                $("#uid1").html("【学号】"+uid+"<br>【当前座位号】"+seatid)
            }else{
                alert("当前座位已存在，请换一个座位!");
            }
        }
    })
}

